<%--
  Created by IntelliJ IDEA.
  User: 爱太阳哟
  Date: 2020/6/1
  Time: 23:09
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>

<head>
    <title>管理页面</title>
    <meta charset="utf-8" />s
    <link rel="stylesheet" type="text/css" href="../../css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="../../css/jquery-confirm.min.css">
    <style>body{
        margin: 0;
        padding: 0;
        height: 100%;
        width: 100%;
    }
    #ul{
        list-style: none;
    }
    #ul button{
        border: 1px solid  black;
    }
    #list td{
        line-height: 30px;
    }
    #list1 td{
        line-height: 30px;
    }
    #chooseInfo{
        margin-top: 9px;
    }
    #b_class,#b_stu{
        margin: 20px;
        float: left;
    }</style>
    <script src="../../js/jquery-3.4.1.min.js"></script>
    <script src="../../js/bootstrap.js"></script>
    <script src="../../js/jquery-confirm.min.js"></script>
</head>

<body>

<div class="jumbotron">
    <div class="jumbotron text-center">
        <nav class="navbar navbar-default navbar-fixed-top" style="width: 100%;">
            <div class="container">
                <div class="collapse navbar-collapse" id="myNavbar">
                    <ul class="nav navbar-nav navbar-right">
                        <li class="nav-item">
                            <a id="book" class="navbar-default active" href="/class/showSearch">班级管理</a>
                        </li>
                        <li class="nav-item">
                            <a id="user" class="navbar-default active" href="/stu/showSearch">学生管理</a>
                        </li>
                        <li class="nav-item" style="margin-top: 8px;">
                            <button id="quit" type="button" class="btn">退出</button>
                        </li>
                    </ul>
                </div>
            </div>
        </nav>
        <div class="container">
            <form id="f_stu" action="/stu/doSearch">
                <div class="input-group">
                    <input type="text" name="id" class="form-control input-lg" style="width: 16.5%;" placeholder="学号">
                    <input type="text" name="name" class="form-control input-lg" style="width: 16.5%;" placeholder="姓名">
                    <input type="text" name="c_id" class="form-control input-lg" style="width: 16.5%;" placeholder="班级id">
                    <input type="text" name="i_id" class="form-control input-lg" style="width: 16.5%;" placeholder="学院id">
                    <input type="text" name="major" class="form-control input-lg" style="width: 16.5%;" placeholder="专业">
                    <input type="text" name="dorm" class="form-control input-lg" style="width: 17.5%;" placeholder="宿舍">
                    <p id="p2_sub" type="button"  class="btn btn-default btn-lg input-group-addon">查询学生</p>
                    <input id="in2_sub" type="submit"  style="display: none;"/>
                </div>
            </form>
        </div>
        <div class="container">
            <div id="b_stu">
                <button class="btn btn-lg btn-success" data-toggle="modal" data-target="#tianjia">添加学生</button>
                <button id="doDel" class="btn btn-lg btn-danger">删除学生</button>
                <span>${msg}</span>
            </div>
            <form id="f_tab" method="get">
            <table id="t_stu" class="table table-striped">
                <thead>
                <tr>
                    <th><input id="selectAll" type="checkbox"/></th>
                    <th>学号</th>
                    <th>姓名</th>
                    <th>班级id</th>
                    <th>学院id</th>
                </tr>
                </thead>
                <tbody id="list1">
                <c:forEach items="${students}" var="stu">
                <tr>
                <td><input name="ids" id="chooseInfo" value="${stu.id}" type="checkbox"/></td>
                <td>${stu.id}</td>
                <td>${stu.name}</td>
                <td>${stu.c_id}</td>
                <td>${stu.i_id}</td>
                <td><button id="change" type="button" class="btn btn-sm btn-primary" data-toggle="modal" data-target="#xiugai">编辑</button></td>
                </tr>
                </c:forEach>
                </tbody>
            </table>
            </form>
        </div>
    </div>
    <div class="modal fade" id="tianjia" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4>添加</h4>
                </div>
                <div class="modal-body">
                    <form role="form" action="/stu/doIns">
                        <div class="container">
                            <div class="row">
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">学号</span>
                                        <input class="form-control" name="id" type="text" placeholder="">
                                    </div>
                                </div>
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">姓名</span>
                                        <input class="form-control" name="name" type="text" placeholder="">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">班级</span>
                                        <select class="form-control" name="c_id">
                                            <c:forEach items="${c_show}" var="c">
                                                <option class="form-control" value ="${c.id}">${c.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">学院</span>
                                        <select class="form-control" name="i_id">
                                            <c:forEach items="${i_show}" var="i">
                                                <option class="form-control" value ="${i.id}">${i.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-block btn-success">确认添加</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
    <div class="modal fade" id="xiugai" role="dialog">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal">&times;</button>
                    <h4>修改</h4>
                </div>
                <div class="modal-body">
                    <form role="form" action="/stu/doUpdate">
                        <div class="container">
                            <div class="row">
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">学号</span>
                                        <input class="form-control change" readonly="readonly" name="id" type="text">
                                    </div>
                                </div>
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">姓名</span>
                                        <input class="form-control change" name="name" type="text">
                                    </div>
                                </div>
                            </div>
                            <div class="row">
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">班级</span>
                                        <select class="form-control" name="c_id">
                                            <c:forEach items="${c_show}" var="c">
                                                <option class="form-control" value ="${c.id}">${c.name}</option>
                                            </c:forEach>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group col-lg-6">
                                    <div class="input-group">
                                        <span class="input-group-addon">学院</span>
                                        <select class="form-control" name="i_id">
                                        <c:forEach items="${i_show}" var="i">
                                            <option class="form-control" value ="${i.id}">${i.name}</option>
                                        </c:forEach>
                                        </select>
                                    </div>
                                </div>
                            </div>
                            <button type="submit" class="btn btn-block btn-success">确认修改</button>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/javascript">
    $(function() {
        $("#p2_sub").click(function(){
            $("#in2_sub").click();
        });
        $("#quit").click(function () {
            window.location.href="/doQuit";
        });
        $('#selectAll').click(function(){
            if($(this).is(':checked')){
                $('input[name="ids"]').each(function(){
                    $(this).prop("checked",true);
                });
            }else{
                $('input[name="ids"]').each(function(){
                    $(this).prop("checked",false);
                });
            };
        });
        $('#doDel').confirm({
            title: '警告!',
            content: '您接下来的操作将会删除所选所有学生的信息,是否继续?',
            buttons: {
                继续: function () {
                    var newUrl = '/stu/doDel';    //设置新提交地址
                    $('#f_tab').attr('action',newUrl);
                    $('#f_tab').submit();
                    $.alert('操作完成!');
                },
                取消: function () {
                    $.alert('操作取消!');
                },
            }
        });
        $('#change').click(function(){
            var $ms = $(this).parent().prevAll();
            var $tb = $('.change');
            for(var i = 0,j = 3;i < 4 ;i++,j--){
                var $m = $ms.eq(j).html();
                $tb.eq(i).attr('value',$m);
            }
        });
    });
</script>

</html>
